/*------------------------------------------------------------------------
 *  Copyright (C) 2010  Luis M. de la Cruz
 *
 *  This file is part of TUNA
 *
 *  TUNA is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  TUNA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ------------------------------------------------------------------------*/

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include <string>
#include <iostream>

#ifdef WITH_GNUPLOT

#ifndef _GNUPLOT_HPP_
#define _GNUPLOT_HPP_

class GNUplot {
public:
    GNUplot() {
	gnuplotpipe = popen("gnuplot","w");
	if (!gnuplotpipe) {
	    throw("Gnuplot not found !");
	}
    }

    ~GNUplot() {
	fprintf(gnuplotpipe,"exit\n");
	pclose(gnuplotpipe);
    }

    void operator()(const std::string& command) {
	fprintf(gnuplotpipe,"%s\n",command.c_str());
	fflush(gnuplotpipe);	
    }

protected:
    FILE *gnuplotpipe;
};

#endif // _GNUPLOT_H_

#endif // WITH_GNUPLOT
